import java.util.ArrayList;

/**
 * represents an event in a game of mule
 * @author Sherman
 *
 */
public class Event {
	//the player passed in
	private Player p;
	//the number of the round
	private int roundNum;
	//the event
	private String event;
	//the description of the event
	private String eventText;
	//the player array passed in (if applicable)
	private ArrayList<Player> pA;
	
	/**
	 * creates an instance of an event
	 * @param p
	 * @param roundNum
	 * @param event
	 */
	public Event(Player p, int roundNum, String event){
		this.p = p;
		this.roundNum = roundNum;
		this.event = event;
	}
	
	public Event(ArrayList<Player> pA, String event){
		this.pA = pA;
		this.event = event;
	}
	
	/**
	 * makes the event happen
	 * @return
	 */
	public String occur(){
		
		//good events 
		if (event.equalsIgnoreCase("package")){//add 3 food and 2 energy
			p.setPlayerResource(0, p.getPlayerResource(0) + 3);
			p.setPlayerResource(1, p.getPlayerResource(1) + 2);
			eventText = p.getName() + ": YOU JUST RECEIVED A PACKAGE FROM THE GT "
					+ "ALUMNI CONTAINING 3 FOOD AND 2 ENERGY UNITS";
		}
		
		else if (event.equalsIgnoreCase("repaid")){//add 2 smithOre
			p.setPlayerResource(2, p.getPlayerResource(2) + 2);
			eventText = p.getName() + ": A TECH STUDENT REPAID YOU FOR YOU HOSPITALITY";
		}
		
		else if(event.equalsIgnoreCase("boughtPC")){//add 8 * roundNum of money
			p.setMoney(p.getMoney() + 8 * roundNum);
			eventText = p.getName() + ": A MUSEUM BOUGHT YOUR PC";
		}
		
		else if(event.equalsIgnoreCase("deadRat")){//add 2 * roundNum of money
			p.setMoney(p.getMoney() + 2 * roundNum);
			eventText = p.getName() + ": YOU SOLD A DEAD RAT'S HIDE";
		}
		
		//bad events
		
		else if(event.equalsIgnoreCase("catBugs")){
			//set to 0 else if player doesn't have enough
			int pMoney = (p.getMoney() - 4 * roundNum > 0) ? p.getMoney() - 4 * roundNum : 0; 
			p.setMoney(pMoney);
			eventText = p.getName() + ": CAT-BUGS ATE YOUR ROOF";
		}
		
		else if(event.equalsIgnoreCase("stolenFood")){//take away half of food
			p.setPlayerResource(0, p.getPlayerResource(0)/2);
			eventText = p.getName() + ": UGA STUDENTS STOLE HALF YOUR FOOD";
		}
		
		else if(event.equalsIgnoreCase("gypsies")){
			//set to 0 else if player doesn't have enough
			int pMoney = (p.getMoney() - 6 * roundNum > 0) ? p.getMoney() - 6 * roundNum : 0; 
			p.setMoney(pMoney);
			eventText = p.getName() + ": GYPSY INLAWS MESSED UP YOUR TOWN";
		}
		
		else if(event.equalsIgnoreCase("mulePlague")){
			for (Player p : pA){
				p.clearMules();
			}
			eventText = "ALL MULES HAVE EXPLODED FROM A COMPUTER VIRUS";
		}
		
		else if(event.equalsIgnoreCase("earthquake")){
			for (Player p : pA){
				p.setPlayerResource(2, 0);
			}
			eventText = "EARTHQUAKE! ALL PLAYER-OWNED SMITHORE HAS BEEN DESTROYED";
		}
		
		else if(event.equalsIgnoreCase("moneyStorm")){
			for (Player p : pA){
				p.setMoney(p.getMoney() + 1000);
			}
			eventText = "IT'S RAINING MONEY. EACH PLAYER COLLECTS $500";
		}
		
		else{
			eventText = p.getName() + ": NOTHING RANDOM HAPPENED TO YOU";
		}
		
		System.out.println(eventText);
		return eventText;
	}
}
